<template>
  <!-- 系统单点域 -->
  <a-select placeholder="单点域" v-bind="$attrs" v-on="$listeners" v-model="currentValue" allowClear>
    <a-spin v-if="fetching" slot="notFoundContent" size="small" />
    <a-select-option v-for="i in pointDomains" :key="i.id" :value="i.id">{{ i.name }}</a-select-option>
  </a-select>
</template>
<script>
import { getPointDomains } from '@/api/system/system'
import Vue from 'vue'

export default {
  inheritAttrs: false,
  props: {
    // v-model绑定的数据
    value: {
      type: [Array, String],
    },
  },
  data() {
    return {
      fetching: false,
      pointDomains: [],
    }
  },
  mounted() {
    const userInfo = Vue.getAcloudProvider().getUserInfo()
    this.getPointDomains()
  },
  methods: {
    getPointDomains() {
      this.fetching = true
      getPointDomains()
        .then((res) => {
          this.fetching = false
          if (res.status === 200) {
            this.pointDomains = res.data
          } else {
            this.$message.error('err:', res.message)
          }
        })
        .catch((res) => {
          this.fetching = false
        })
    },
  },
  computed: {
    // 转换绑定的选中数据，与v-model同步
    currentValue: {
      get: function () {
        return this.value
      },
      set: function (value) {
        this.$emit('input', value)
      },
    },
  },
}
</script>
